package com.lovo.psc.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.psc.bean.VendorProductBean;
import com.lovo.psc.mapper.IVendorProductMapper;
import com.lovo.psc.service.IVendorProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class IVendorProductServiceImpl implements IVendorProductService {

    @Autowired
    private IVendorProductMapper mapper;


    @Override
    public List<VendorProductBean> findAll() {
        QueryWrapper<VendorProductBean> qw  = new QueryWrapper<>();
        qw.eq("p_status",0);
        return mapper.selectList(qw);
    }

    @Override
    public VendorProductBean findByName(String name) {
        QueryWrapper<VendorProductBean> qw = new QueryWrapper<>();
        qw.eq("p_productName",name);
        qw.eq("p_status",0);
        return mapper.selectOne(qw);
    }

    @Override
    public List<VendorProductBean> findTypeLst() {
        List<VendorProductBean> lst = mapper.findTypeLst();
        return lst;
    }

    @Override
    public List<VendorProductBean> findProductTypeLst(String type) {
        QueryWrapper<VendorProductBean> qw = new QueryWrapper<>();
        qw.eq("p_type", type);
        qw.eq("p_status","0");
        return mapper.selectList(qw);
    }

    @Override
    public List<VendorProductBean> findAllProduct(int id) {
        return mapper.findAllProduct(id);
    }

    @Override
    public void add(VendorProductBean vendorproduct) {
        mapper.insert(vendorproduct);

    }

    @Override
    public void update(String userId, int number) {
        VendorProductBean bean = mapper.selectById(userId);
        bean.setNum(number);
        mapper.updateById(bean);
    }


    @Override
    public void del(String ber) {
        VendorProductBean bean = mapper.selectById(ber);
        bean.setStatus(1);
        mapper.updateById(bean);

    }
}
